package com.muse.udp;

import java.net.DatagramPacket;
import java.net.DatagramSocket;

/**
 * @description
 * @author: muse
 **/
public class UDPServer {
    public final static int PORT = 8080;
    public static void main(String[] args) throws Throwable {
        DatagramSocket socket = new DatagramSocket(PORT);
        for (;;) {
            DatagramPacket recePacket = new DatagramPacket(new byte[10], 10);
            socket.receive(recePacket);
            String result = new String(recePacket.getData(), 0, recePacket.getLength(), "ASCII");
            System.out.println("Receive = " + result);
            byte[] ack = "ACK".getBytes();
            DatagramPacket sendPacket = new DatagramPacket(ack, ack.length, recePacket.getAddress(),
                    recePacket.getPort());
            socket.send(sendPacket);
        }
    }
}
